package widget.dress
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	
	import widget.common.utils.DisplayObjectUtil;
	import widget.dress.mode.ActionModel;
	
	public class DressViewer extends Sprite{
		
		/**
		 * PNG的人物动作图板数组，按动作、方向和帧保存
		 */
		private var dressList : Vector.<ActionModel> = null;
		
		//人物图板容器
		private var dressContainer : Sprite = null;
	
		public function DressViewer()
		{
			super();
			dressContainer = new Sprite();
			dressList = new Vector.<ActionModel>;
			dressContainer.x = 5;
			dressContainer.y = -65;
			dressContainer.scaleX = 0.5;
			dressContainer.scaleY = 0.5;
			
			addChild(dressContainer);
		}
		
		public function addDress(bitmap:Bitmap):void
		{
			if(bitmap == null) return;
			DisplayObjectUtil.clearDisplayContainer(dressContainer);
			dressContainer.addChild(bitmap);
		}
		
		public function removeDress():void
		{
			while(dressContainer.numChildren > 0){
				dressContainer.removeChildAt(0);
			}
		}
		
		public function getDataByAction(act:uint):ActionModel
		{
			for each(var model:ActionModel in dressList){
				if(model.action == act){
					return model;
				}
			}
			return null;
		}
		
		public function get dataList():Vector.<ActionModel>
		{
			return dressList;
		}
		
		public function dispose():void
		{
			DisplayObjectUtil.clearDisplayContainer(this);
			DisplayObjectUtil.clearDisplayContainer(dressContainer);
			dressList.splice(0,dressList.length);
			dressList = null;
			dressContainer = null;
		}
	}
}